﻿using System.Collections.Generic;
using System.Linq;
using log4net;
using SmallBusinessKit.DataAccess.Interfaces;
using SmallBusinessKit.Interfaces;
using SmallBusinessKit.Models.Entities;

namespace SmallBusinessKit.Domains
{
    public class PeopleDomain : IPersonDomain
    {
        #region Properties

        private static readonly ILog _log = LogManager.GetLogger(typeof(PeopleDomain));

        private readonly IPersonRepository _personRepository;

        #endregion

        #region Methods

        public PeopleDomain(IPersonRepository personRepository)
        {
            _personRepository = personRepository;
        }

        public IQueryable<Person> GetAllPersons()
        {
            var query = _personRepository.GetAsQueryable().Where(i => i.IsVisible).OrderBy(i => i.Id);

            _log.DebugFormat("Retrieved Query Expression: {0}", query.Expression);

            return (query);
        }

        public IEnumerable<Person> GetAllPersonsList()
        {
            var results = _personRepository.GetAsQueryable().Where(i => i.IsVisible).ToList();

            _log.DebugFormat("Retrieved Query Expression: {0}", results.Count);

            return (results);
        }

        #endregion
    }
}
